﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


public partial class ImagesManager : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request.QueryString["al"] != null)
            {
                int iID = int.Parse(Request.QueryString["al"].ToString());
                load_ALL_IMAGES(iID);
            }
        }
    }


    public void load_ALL_IMAGES(int iAlbumID)
    {
        aAddImages.HRef = "AddUpdateImages.aspx?al=" + iAlbumID.ToString();
        ltAlbumName.Text = "Album : "  + BusLogic.Album.get_ALBUM(iAlbumID).Tables[0].Rows[0]["NAME"].ToString();

        if (BusLogic.Images.get_ALL_IMAGES(iAlbumID).Tables[0].Rows.Count > 0)
        {
            divError.Visible = false;
            rpImages.DataSource = BusLogic.Images.get_ALL_IMAGES(iAlbumID);
            rpImages.DataBind();
        }
        else
        {
            rpImages.DataSource = BusLogic.Images.get_ALL_IMAGES(iAlbumID);
            rpImages.DataBind();

            divError.Visible = true;
            ltError.Text = "Album chưa có ảnh !";
        }
        
    }
    protected void rpImages_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "DeleteImage")
        {
            int ID = Convert.ToInt32(e.CommandArgument);
            BusLogic.Images.remove_IMAGES(ID);
            
            int iAl = int.Parse(Request.QueryString["al"].ToString());
            load_ALL_IMAGES(iAl);
        }

        if (e.CommandName == "UpdateImage")
        {
            int iAl = int.Parse(Request.QueryString["al"].ToString());
            
            int ID = Convert.ToInt32(e.CommandArgument);
            Response.Redirect("AddUpdateImages.aspx?al=" + iAl.ToString() + "&id=" + ID.ToString());
        }
    }
}
